<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 对象转换为字符串
      //   function getstring() {}

      //   function getstring1() {}

      let obj = { uname: "陈伟霆", sex: "男", age: "18" };
      // 对象转字符串
      function getstring(obj) {
        let list = [];
        for (let k in obj) {
          list.push(k);
          list.push("=");
          list.push(obj[k]);
          list.push("&");
        }
        return list.join("").slice(0, list.join("").length - 1);
      }
      console.log(getstring(obj));

      // let josn = '{"uname":"陈伟霆","sex":"男","age":"18"}';
      // let star = JSON.parse(josn)
      // console.log(star);

      let josn = "uname=陈伟霆&sex=男&age=18";
      function getJOSN(josn) {
        let star = josn.split("&");
        let arr = {};
        star.forEach(function (i) {
          arr[i.split("=")[0]] = i.split("=")[1];
        });
        return arr;
      }
      console.log(getJOSN(josn));













      
      //   function getstring1(josn) {
      //     let satr = josn.split("&");
      //     let arr = {};
      //     satr.forEach(function (item) {
      //       arr[item.split("=")[0]] = item.split("=")[1];
      //     });
      //     return arr;
      //   }
      //   console.log(getstring1(josn));
    </script>
  </body>
</html>
